/******************************************************************************
 *
 * ngcap - network sniffer using raw sockets
 *
 * Author:        cr
 * E-mail:        cr.at.netgarage.org
 * WWW:           http://www.netgarage.org
 * Copyright (C): 2009 by cr
 *
 * This file is part of ngcap.
 *
 * ngcap is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ngcap is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ngcap.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/

#include <cstdlib>
#include <iostream>
#include "ngcap.hpp"
bool Trace::debug=true;
bool Trace::blog=false;
std::string Trace::logfile="logfile.log";

int main(int argc, char* argv[])
{
    Trace t("NGCap");
    NGCap ngc;
    const char usage[] =
    "Usage: ./ng-cap++ [options]";
    int opt=0;

    if(argc>1)
    while((opt=getopt(argc, argv, "i:f:"))!=-1)
        switch(opt) {
            case 'i' : ngc.setInterface(optarg);
            case 'f' : ngc.setFilter(optarg);
            default: std::cout<<usage;
        }
    ngc.work();
    return 0;
}

void NGCap::work()
{
    Trace t("NGCap::work");
    PacketHandler* ph;
    PacketFilter* pf=new PacketFilter(filter);
    try{
        ph=new PacketHandler(pf);
        ph->startThreads(ph);
    } catch(...){
        delete pf;
        delete ph;
        exit(-1);
    }
    delete pf;
    delete ph;
}
